<template>
	<view class="center">
		<view class="loginout">
			<u-tag text="退出登录" @click="loginOut()" type="warning" shape="circleLeft"/>
		</view>
		<view class="t_x_style">
				<u-avatar size="large" :src="token ? src : avatarUrl" mode="circle" @click="toggleavatar"></u-avatar>
			</view>
			<p class="t_x_style">{{mingcheng}}</p>
			
		<view class="center-list">		
			<view class="center-list-item border-bottom" @click="my()">
				<text class="glyphicon glyphicon-send" style="color: #9d9dff; margin-top: 13px; margin-left: 3px; font-size: 15px;"></text>
				<text class="list-text" style="margin-left: 10px;">我发布的</text>
				<text class="navigat-arrow" style="float: right;">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom" @click="draft()">
				<text class="glyphicon glyphicon-list" style="color: #a9ffc2; margin-top: 13px; margin-left: 3px; font-size: 15px;"></text>
				<text class="list-text" style="margin-left: 10px;">草稿</text>
				<text class="navigat-arrow" style="float: right;">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom" @click="Modify()">
				<text class="glyphicon glyphicon-home" style="color: #ff74fd; margin-top: 13px; margin-left: 3px; font-size: 15px;"></text>
				<text class="list-text" style="margin-left: 10px;">修改密码</text>
				<text class="navigat-arrow" style="float: right;">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
/*
 * tabbar我的页面
 */
	import api from '../../util/api.js';
	import util, { parGetData, parSetData, checklogin } from '../../common/util';
	import 'bootstrap/dist/css/bootstrap.min.css';
	import "bootstrap/dist/css/bootstrap.css";
export default {
	data() {
		return {
			src: '',
			text: '中国',
			mingcheng:'linker',
			avatarUrl: '',
			openid: '',
			token: '',
			userinfo: '',
			appusername: ''
		};
	},
	onShow() {
		this.checkstat();
	},
	onLoad() {
		this.token = uni.getStorageSync('token');
	},
	methods: {
		Modify(){
			uni.navigateTo({
				url: '/pages/ModifyInfo/ModifyInfo'
			});
		},
		draft(){
			uni.navigateTo({
				url: '/pages/draft/draft'
			});
		},
		gologinpage(){
			// #ifdef MP-WEIXIN
			uni.navigateTo({
				url: '/pages/login/login.vue'
			});
			// #endif
		},
		toggleavatar: async function() {
			// 更换头像
			var self = this;
			uni.chooseImage({
				count: 1,
				sizeType: 'compressed ',
				success: res => {
					self.image = res.tempFilePaths[0];
					uni.showLoading({
						title: '上传中',
						icon: 'none'
					});
					uni.uploadFile({
						url: api.uploadAttachs,
						filePath: res.tempFilePaths[0],
						name: 'image',
						header: {
							auth: util.httpauth
						},
						success: res => {
							res.data = JSON.parse(res.data);
							if (res.statusCode == 200 && res.data.code < 1) {
								this.$set(self.userinfo, 'avatar', res.data.imageurl);
								// 存入用户信息
								uni.setStorageSync('userinfo', parSetData(self.userinfo));
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								});
							}
						},
						complete: function() {
							uni.hideLoading();
						}
					});
				}
			});
		},
		gobind() {
			if (this.token && !this.appusername) {
				// 去绑定
				this.gologinpage()
				return false;
			}
		},
		my() {
			uni.navigateTo({
				url: '/pages/myRelease/myRelease'
			});
		},
		checkstat() {
			var logininfo = util.checklogin();
			this.openid = logininfo.openid;
			this.userinfo = logininfo.userinfo;
			this.token = logininfo.token;
			this.appusername = logininfo.appusername;
		},
		login(res) {
			util.logincomm(res, this);
		},
		loginOut(){
			uni.clearStorage();
			uni.showToast({
				icon:'none',
				title:'退出登录成功'
			})
			uni.navigateTo({
				url:'../login/login'
			})
			//清除缓存
			try{
				uni.clearStorageSync();
			} catch(e){
				
			}
		}
	}
};
</script>

<style>
.logo {
	position: relative;
	background: #f44336;
}
.center {
	overflow: hidden;
}
.logo-title {
	color: #ffffff;
}
.appusername {
	/* font-size: 20rpx; */
	color: #fff;
	/* margin-left: 10rpx; */
}
.center .list-icon {
	color: #f44336;
}
#loginbutton {
	display: flex;
	margin: 0;
	border: none;
	box-shadow: none;
	background: transparent;

	z-index: 999;
	color: #ffffff;
	width: auto;
	position: absolute;
	top: 0;
	left: 0;
	text-align: center;
	width: 100%;
	height: 100%;
	align-items: center;
	justify-content: center;
}
#loginbutton:after,
#loginbutton:before {
	display: none;
}
.t_x_style{
	background-color: #2acc73;
	display: flex;
	justify-content: center;
	font-size: 35px;
	padding-bottom: 20px;
}
.loginout{
		position: absolute;
		top: 40rpx;
		right: 0;
	}
</style>
